package com.utils.failureanalysis.data.model;

import java.io.File;

/**
 * 路径模型
 * 包含一个模块下的各数据存放路径
 * 按此路径分析可得出：单任务id单模块分析数据
 */
public class FilePath {

    // test_result_failures.html路径
    // D:\jenkins\workspace\Attila-4-Lite-功能-RW-2018-1-15-18-48-14-339_Contacts\android-cts\results\test_result_failures.html
    private File failResultFilePath;

    // test_result.xml路径
    // D:\jenkins\workspace\Attila-4-Lite-功能-RW-2018-1-15-18-48-14-339_Contacts\android-cts\results\test_result.xml
    private File ResultFilePath;

    // host_log_2910328503940944160.zip路径
    // D:\jenkins\workspace\Attila-4-Lite-功能-RW-2018-1-15-18-48-14-339_Contacts\android-cts\logs\2018.06.22_05.01.04\host_log_2910328503940944160.zip
    private File hostLogZipFilePath;

    public FilePath() {
        super();
    }

    public FilePath(File failResultFilePath, File resultFilePath, File hostLogZipFilePath) {
        super();
        this.failResultFilePath = failResultFilePath;
        ResultFilePath = resultFilePath;
        this.hostLogZipFilePath = hostLogZipFilePath;
    }

    public File getFailResultFilePath() {
        return failResultFilePath;
    }

    public void setFailResultFilePath(File failResultFilePath) {
        this.failResultFilePath = failResultFilePath;
    }

    public File getResultFilePath() {
        return ResultFilePath;
    }

    public void setResultFilePath(File resultFilePath) {
        ResultFilePath = resultFilePath;
    }

    /**
     * 获取host_log_2910328503940944160.zip路径
     *
     * @return
     */
    public File getHostLogZipFilePath(String hostLogFolderPath) {
//		TODO:此处需要fix bug，logs目录下可能有多个log文件夹，需要按时间确定需要的文件夹，此处默认选取第一个文件夹下的log
//		2018.06.22_22.02.57
        File filePath = new File(hostLogZipFilePath + "".replace("results.*", "") + "\\logs");
        for (String path : filePath.list()) {
            if (path.contains(hostLogFolderPath)) {
                filePath = new File(filePath + "\\" + path);
                break;
            }
        }
        for (String path : filePath.list()) {
            if (path.matches("host_log_.*"))
                return new File(filePath + "\\" + path);
        }
        System.out.println("-------Can't find host_log.zip file!-------");
        return new File("");
    }

    public void setHostLogZipFilePath(File hostLogZipFilePath) {
        this.hostLogZipFilePath = hostLogZipFilePath;
    }

}
